package com.qczl.pme.controller.stb;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.qczl.model.Json;
import com.qczl.pme.service.MettingRoomService;
import com.qczl.pme.vo.CameraVo;

/**
 * 会议室控制器
 * @author SongR
 *
 */
@Controller
@RequestMapping(value="/stb/mettingroom")
public class StbMettingRoomController {
	
	Logger log = Logger.getLogger(this.getClass());
	@Autowired
	MettingRoomService service;
	
	/**
	 * 获取县级会场
	 * @version v1
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/county/v1",method={RequestMethod.GET,RequestMethod.POST})
	public Json getCountyV1(String stbno,int start,int size){
		Json j = new Json();
		try {
			List<CameraVo> vos = service.getCountyV1(stbno,start,size);
			if(vos.size()>0){
				j.setSize(service.countCountyV1(stbno));
				j.setMsg("成功获取县级会议室！");
				j.setResult(vos);
				j.setLength(new Long(vos.size()));
			}else{
				j.setSize(new Long(0));
				j.setState(404);
				j.setMsg("暂无县级会议室");
			}
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("获取县级会议室异常！");
			log.error("获取县级会议室接口异常！",e);
		}
		return j;
	}
	
	
	/**
	 * 获取村级会议室
	 * @version v1
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/village/v1",method={RequestMethod.GET,RequestMethod.POST})
	public Json getVillageV1(String stbno,String townid,int start,int size){
		Json j = new Json();
		try {
			List<CameraVo> vos = service.getVillageV1(stbno,townid,start,size);
			if(vos.size()>0){
				j.setSize(service.countVillageV1(stbno,townid));
				j.setMsg("成功获取村级会议室！");
				j.setResult(vos);
				j.setLength(new Long(vos.size()));
			}else{
				j.setSize(new Long(0));
				j.setState(404);
				j.setMsg("暂无村级会议室");
			}
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("获取镇级会议室异常！");
			log.error("获取镇级会议室接口异常！",e);
		}
		return j;
	}
	
	/**
	 * 获取直属部门会场
	 * @version v1
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/branch/v1",method={RequestMethod.GET,RequestMethod.POST})
	public Json getBranch(String stbno,int start,int size){
		Json j = new Json();
		try {
			List<CameraVo> vos = service.getBranchV1(stbno,start,size);
			if(vos.size()>0){
				j.setSize(service.countBranchV1(stbno));
				j.setMsg("成功获取直属部门会场！");
				j.setResult(vos);
				j.setLength(new Long(vos.size()));
			}else{
				j.setSize(new Long(0));
				j.setState(404);
				j.setMsg("暂无直属部门会场");
			}
		} catch (Exception e) {
			j.setSuccess(false);
			j.setMsg("获取直属部门会场异常！");
			log.error("获取直属部门会场接口异常！",e);
		}
		return j;
	}
	
}
